<?php

include "fonctions.php";
head_html("Cr&eacute;ation de Jeux");
en_tete();
?>

	<div id="contenu">
		<?php
			menu_lateral_droit();
		?>
		<div id="texte">
			<?php
			vousetesici("Cr&eacute;ation de jeux");
			db_connect();

			//Creation en base du cadavre excquis
			if(isset($_POST['validerCadavre'])){
				if (isset($_POST['cadavre']) && isset($_POST['name']) && $_POST['name'] != "")
				{
					$req_exo = "INSERT INTO LMLP.exercices (idTypeJeu,etat,nom) VALUES (1,\"actif\",\"".$_POST['name']."\");";
			
					mysql_query($req_exo) or die ("Insertion exercices" + mysql_error());
					$id = mysql_insert_id();
					$vitrine = false;
					if(isset($_POST['vitrine'])){ 
						$Col1_Array = $_POST['vitrine']; 
						foreach($Col1_Array as $selectValue){ 
						$vitrine = $selectValue; 
					}          
					}
					$req_cadavre ="INSERT INTO LMLP.cadavre_exquis (idExercice,vitrine) VALUES (".$id.",".$vitrine.")";
					mysql_query($req_cadavre) or die (mysql_error());
					
					$req_cadavre ="INSERT INTO LMLP.phrases (partieCache,partieVisible,idCadavreExcquis) VALUES (\"\",\"\",".$id.")";
					mysql_query($req_cadavre) or die (mysql_error());
					
						$Col1_Array = $_POST['cadavre']; 
						foreach($Col1_Array as $selectValue){ 
							$req_atelier = "INSERT INTO LMLP.exercices_ateliers (idExercice,nomAtelier) VALUES (".$id.",\"".$selectValue."\");";
							mysql_query($req_atelier) or die (mysql_error());
							echo "<script>
							
							alert(\"Le cadavre a été créé pour l'atelier ".$selectValue."\");
							</script>";
		
						}
						echo '<meta http-equiv="refresh" content="3; URL=creation_jeux.php">';
				
				}else{
					if(!isset($_POST['cadavre'])){
						echo "<p class=\"red\">Veuillez s&eacute;lectionner au moins un atelier.</p>";
					}
					
					if(!isset($_POST['name']) || $_POST['name'] == ""){
						echo "<p class=\"red\">Veuillez entrer un nom de cadavre</p>";
					}
					
					
				}
			}
			
			
			echo "<h1>Cr&eacute;ation de jeux</h1>";
			echo "<h2>Le cadavre exquis</h2>";
			//formulaire pour la creation du cadavre excquis
				$req = "SELECT nomAtelier FROM LMLP.ateliers;";
				$result = mysql_query($req) or die (mysql_error());
				$nb = mysql_num_rows($result);	
				
				
				echo "<form name=\"inscription\" method=\"post\" action=\"creation_jeux.php\">";
				echo"<ul id=\"jeux\">";
				echo "<li>";
				echo "<p>Atelier:";
				echo "<select name=\"cadavre[]\" multiple=\"multiple\" required>";
					while ($row = mysql_fetch_assoc($result)) {
						echo "<option value=\"".$row['nomAtelier']."\">".$row['nomAtelier']."</option>";
					}
				echo "</select></p>";
				echo "</li>";
				echo "<li>";
				echo "<p>Visibilit&eacute;";
				echo "<select name=\"vitrine[]\">";
						echo "<option value=\"false\">Masqu&eacute;</option>";
						echo "<option value=\"true\">En vitrine</option>";
				
				echo "</select></p>";
				echo "</li>";
				echo "<li>";
				echo "<p>Nom du cadavre ";
				echo "<input type=\"text\" name=\"name\"/ required>";
						
				echo "</p>";
				echo "</li>";
				$test="ok";
				echo "<input style=\"display:none;\"  type=\"text\" name=\"test\" value=\"".$test."\">";
				echo "<li>";
				echo "<p>Cr&eacute;er un cadavre exquis";
				echo "<input type=\"submit\" name=\"validerCadavre\" value=\"Valider\"/ ></p>";
				echo "</li>";
				echo"</ul>";
				echo "</form>";
				
				
				
				
				echo "<h2>Le carr&eacute; magique</h2>";
				
				
				
				$req = "SELECT nomAtelier FROM LMLP.ateliers;";
				$result = mysql_query($req) or die (mysql_error());
				$nb = mysql_num_rows($result);	
				
				echo "<form name=\"inscription\" method=\"post\" action=\"creation_carre.php\">";
				
				echo "<p>Cr&eacute;er un carre magique";
				echo "<input type=\"submit\" name=\"validerCarre\" value=\"Valider\"/></p>";
				echo "</form>";
				
			?>
				
	
		</div>
	</div>
	<?php
		pied_page();
	?>
</body>
</html>
